/*
This codefile contains the functionality of the "AbstractApplication" 
component, specified in the design report ("tussenrapport.doc").

Author:			Geert, Daan
Version: 		1
Last modified:	09-06-11
*/

// initializing function for this component
void AbstractApplication_Initialize ()
{
	// initialize global variables
	
}

/*
This function is triggered when the elevator cabin stops at a floor. We send a message over the serial connection, according to the defined protocol (see "tussenrapport.doc").
*/
void AbstractApplication_ArrivedAt (int floor)
{
	Serial_Write(floor+0xF1);
}

/*
This function is triggered when the elevator receives a call to a floor. We send a message over the serial connection, according to the defined protocol (see "tussenrapport.doc").
*/
void AbstractApplication_MovingTo (int floor)
{
	Serial_Write(floor+0x01);
}

/*
This function is triggered when the elevator goes into emergency mode. We send a message over the serial connection, according to the defined protocol (see "tussenrapport.doc").
*/
void AbstractApplication_NewEmergency ()
{
	Serial_Write(0x0E);
}

/*
This function is triggered when the elevator goes back to normal mode after being in emergency mode. We send a message over the serial connection, according to the defined protocol (see "tussenrapport.doc").
*/
void AbstractApplication_ResumeOperations ()
{
	Serial_Write(0x0F);
}

/*
This function is triggered when a new message is received from the external application over the serial connection. We handle the message according to the defined protocol (see "tussenrapport.doc").
*/
void AbstractApplication_ParseMessage (unsigned char ch)
{
	switch(ch)
	{
		case 0x01:
			ElevatorLogic_GoTo(0);
			break;
			
		case 0x02:
			ElevatorLogic_GoTo(1);
			break;
			
		case 0x03:
			ElevatorLogic_GoTo(2);
			break;
			
		case 0x04:
			ElevatorLogic_GoTo(3);
			break;
			
		case 0x0E:
			ElevatorLogic_CallEmergency();
			break;
			
		case 0x0F:
			ElevatorLogic_ResumeOperations();
			break;
	}
}